import { localCache } from '@/utils/cache'
import { closeNprogress, openNprogress } from '@/utils/nprogress'
import { createRouter, createWebHashHistory } from 'vue-router'

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      redirect: '/index',
      component: () => import('@/views/layout/index.vue'),
      children: [
        {
          path: '/index',
          name: 'index',
          component: () => import('@/views/index/index.vue')
        },
        {
          path: '/humanize',
          name: 'humanize',
          component: () => import('@/views/humanize/humanize.vue')
        },
        {
          path: '/detector',
          name: 'detector',
          component: () => import('@/views/detector/detector.vue')
        },
        {
          path: '/detection',
          name: 'detection',
          component: () => import('@/views/detection/detection.vue')
        },
        {
          path: '/privacy',
          name: 'privacy',
          component: () => import('@/views/privacy/privacy.vue')
        },

        {
          path: '/termsOfService',
          name: 'termsOfService',
          component: () => import('@/views/termsOfService/termsOfService.vue')
        },
        {
          path: '/refundPolicy',
          name: 'refundPolicy',
          component: () => import('@/views/refundPolicy/refundPolicy.vue')
        },
        {
          path: '/about',
          name: 'about',
          component: () => import('@/views/about/about.vue')
        },
        {
          path: '/originality',
          name: 'originality',
          component: () => import('@/views/originality/originality.vue')
        },
        {
          path: '/gptzero',
          name: 'gptzero',
          component: () => import('@/views/gptzero/gptzero.vue')
        },
        {
          path: '/copyleaks',
          name: 'copyleaks',
          component: () => import('@/views/copyleaks/copyleaks.vue')
        },
        {
          path: '/zerogpt',
          name: 'zerogpt',
          component: () => import('@/views/zerogpt/zerogpt.vue')
        },
        {
          path: '/contentatscale',
          name: 'contentatscale',
          component: () => import('@/views/contentatscale/contentatscale.vue')
        }
      ]
    }
  ]
})

// 前置路由守卫
router.beforeEach((to) => {
  // 路由跳转打开loading
  openNprogress()
})

// 后置路由守卫
router.afterEach(() => {
  // 路由跳转完成关闭loading
  closeNprogress()
})

export default router
